﻿#include "widget.h"
#include "ui_widget.h"

#include <QDebug>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    loadFile();
}

Widget::~Widget()
{
    delete ui;
    delete[] m_file;
}

void Widget::loadFile()
{
    m_file = new char[1024];
    strcpy(m_file, "./config.ini");

    m_myIni = new MyIni(m_file);
}

void Widget::readFile()
{
    string str = m_myIni->getValueString("Activity","name");
    //string转化为QString,fromStdString存在乱码
    qDebug()<<QString::fromLocal8Bit(str.c_str());

    ui->label->setText(QString::fromLocal8Bit(str.c_str()));
}

void Widget::saveFile()
{
    QString str = ui->lineEdit->text();
    m_myIni->writeKeyValue("Activity","name",(const char *)str.toLocal8Bit());
}

//读取
void Widget::on_pushButton_clicked()
{
    readFile();
}

//写入
void Widget::on_pushButton_2_clicked()
{
    saveFile();
}
